/* 
 * File:   Texture.cpp
 * Author: RedEyedKiller
 * 
 * Created on 20 Ιούλιος 2011, 7:45 πμ
 */

#include "Texture.h"
#include "Image.h"

namespace gl
{

Texture::Texture()
{
    ID = 0;
	width = 0;
	height = 0;
}

Texture::~Texture()
{
    if(ID != 0)
        glDeleteTextures( 1, &ID );
}

bool Texture::Load(const char* filename)
{
    sdl::Image* image = new sdl::Image( filename );
    ID = image->ConvertToTexture( );
    
    if( ID != 0 )
    {
        width = image->GetWidth( );
        height = image->GetHeight( );

        delete image;
        return true;
    }
    else
    {
        delete image;
        return false;
    }

}

void Texture::Apply() const
{
    glBindTexture( GL_TEXTURE_2D, ID );
}

unsigned int Texture::GetHeight() const
{
    return height;
}

unsigned int Texture::GetWidth() const
{
    return width;
}

unsigned int Texture::GetID() const
{
    return ID;
}

}
